﻿namespace Agent
{
    using Agent.Dialogs;
    using OpenVPN.States;
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Net;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class MainMenuPanel : UserControl, IComponentConnector
    {
        private AgentMessageHandler a;
        internal Image aa;
        internal Image ab;
        internal Image ac;
        private bool ad;
        [CompilerGenerated]
        private static Func<ConnectionButton, string> ae;
        [CompilerGenerated]
        private static ThreadStart af;
        private AgentExitHandler b;
        private bool c;
        private SynchronizationContext d;
        internal Label e;
        internal Image f;
        internal StackPanel g;
        internal Label h;
        internal Label i;
        internal StackPanel j;
        internal Label k;
        internal Label l;
        internal StackPanel m;
        internal Label n;
        internal Label o;
        internal StackPanel p;
        internal Label q;
        internal Label r;
        internal StackPanel s;
        internal Label t;
        internal Label u;
        internal Label v;
        internal Image w;
        internal ScrollViewer x;
        internal StackPanel y;
        internal Image z;

        public MainMenuPanel()
        {
            Action action = null;
            Action action2 = null;
            this.InitializeComponent();
            this.e();
            AgentUser.a().a(new EventHandler(this.LicenseUpdated));
            this.aa.IsEnabled = false;
            this.ab.IsEnabled = false;
            this.ac.IsEnabled = false;
            if (action == null)
            {
                action = new Action(this.d);
            }
            ConfigManager.b(action);
            if (action2 == null)
            {
                action2 = new Action(this.c);
            }
            ConfigManager.d(action2);
            if (ConfigManager.r())
            {
                this.k.Foreground = this.q.Foreground = this.n.Foreground = Brushes.Gray;
                this.j.IsEnabled = this.m.IsEnabled = this.p.IsEnabled = false;
            }
        }

        [CompilerGenerated]
        private void a()
        {
            if (ConfigManager.a())
            {
                SendOrPostCallback d = null;
                SendOrPostCallback callback2 = null;
                string a = "";
                try
                {
                    <>c__DisplayClass15 class3;
                    a = new WebClient().DownloadString("https://thesafety.us/billing/gui/ip.php");
                    a = a.Trim(new char[] { ' ', '\t', '\r', '\n' });
                    if (d == null)
                    {
                        d = new SendOrPostCallback(class3.d);
                    }
                    this.d.Send(d, null);
                    if (callback2 == null)
                    {
                        callback2 = new SendOrPostCallback(class3.c);
                    }
                    this.d.Send(callback2, null);
                }
                catch (Exception exception)
                {
                    ConfigManager.a("btnMyIp_Click", exception);
                }
                try
                {
                    if (a == "")
                    {
                        <>c__DisplayClass17 class2;
                        a = new WebClient().DownloadString("http://www.myip.ru/get_ip.php");
                        char[] separator = new char[] { '>', '<' };
                        string[] b = a.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                        this.d.Send(new SendOrPostCallback(class2.d), null);
                        this.d.Send(new SendOrPostCallback(class2.c), null);
                    }
                }
                catch (Exception exception2)
                {
                    ConfigManager.a("btnMyIp_Click", exception2);
                }
            }
        }

        public void a(AgentExitHandler A_0)
        {
            AgentExitHandler handler2;
            AgentExitHandler b = this.b;
            do
            {
                handler2 = b;
                AgentExitHandler handler3 = (AgentExitHandler) Delegate.Remove(handler2, A_0);
                b = Interlocked.CompareExchange<AgentExitHandler>(ref this.b, handler3, handler2);
            }
            while (b != handler2);
        }

        public void a(AgentMessageHandler A_0)
        {
            AgentMessageHandler handler2;
            AgentMessageHandler a = this.a;
            do
            {
                handler2 = a;
                AgentMessageHandler handler3 = (AgentMessageHandler) Delegate.Remove(handler2, A_0);
                a = Interlocked.CompareExchange<AgentMessageHandler>(ref this.a, handler3, handler2);
            }
            while (a != handler2);
        }

        [CompilerGenerated]
        private static string a(ConnectionButton A_0)
        {
            return A_0.h();
        }

        [CompilerGenerated]
        private void a(object A_0)
        {
            this.aa.IsEnabled = true;
            this.ab.IsEnabled = false;
            this.ac.IsEnabled = false;
            this.aa.ToolTip = e.c("Connect");
            this.aa.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/connect.png"));
            this.ab.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/mono_disconnect.png"));
            this.ac.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/mono_send.png"));
        }

        private void a(string A_0)
        {
            if (this.a != null)
            {
                AgentMessageEventArgs args = new AgentMessageEventArgs();
                args.a(NotificationType.Info);
                args.a(e.c("MyIp") + " " + A_0);
                this.a(this, args);
            }
        }

        [DebuggerNonUserCode, EditorBrowsable(EditorBrowsableState.Never)]
        private void a(int A_0, object A_1)
        {
            switch (A_0)
            {
                case 1:
                    ((MainMenuPanel) A_1).Loaded += new RoutedEventHandler(this.UserControl_Loaded);
                    return;

                case 2:
                    ((Image) A_1).MouseLeftButtonUp += new MouseButtonEventHandler(this.Image_MouseLeftButtonUp);
                    return;

                case 3:
                    this.e = (Label) A_1;
                    return;

                case 4:
                    this.f = (Image) A_1;
                    this.f.MouseLeftButtonUp += new MouseButtonEventHandler(this.btnMainMenuClose_Click);
                    return;

                case 5:
                    this.g = (StackPanel) A_1;
                    this.g.MouseUp += new MouseButtonEventHandler(this.btnMyIp_Click);
                    return;

                case 6:
                    this.h = (Label) A_1;
                    return;

                case 7:
                    this.i = (Label) A_1;
                    return;

                case 8:
                    this.j = (StackPanel) A_1;
                    this.j.MouseUp += new MouseButtonEventHandler(this.btnMyAccount_Click);
                    return;

                case 9:
                    this.k = (Label) A_1;
                    return;

                case 10:
                    this.l = (Label) A_1;
                    return;

                case 11:
                    this.m = (StackPanel) A_1;
                    this.m.MouseUp += new MouseButtonEventHandler(this.btnSettings_Click);
                    return;

                case 12:
                    this.n = (Label) A_1;
                    return;

                case 13:
                    this.o = (Label) A_1;
                    return;

                case 14:
                    this.p = (StackPanel) A_1;
                    this.p.MouseUp += new MouseButtonEventHandler(this.btnManagement_MouseUp);
                    return;

                case 15:
                    this.q = (Label) A_1;
                    return;

                case 0x10:
                    this.r = (Label) A_1;
                    return;

                case 0x11:
                    this.s = (StackPanel) A_1;
                    this.s.MouseUp += new MouseButtonEventHandler(this.btnHelp_Click);
                    return;

                case 0x12:
                    this.t = (Label) A_1;
                    return;

                case 0x13:
                    this.u = (Label) A_1;
                    return;

                case 20:
                    this.v = (Label) A_1;
                    return;

                case 0x15:
                    this.w = (Image) A_1;
                    this.w.MouseLeftButtonUp += new MouseButtonEventHandler(this.imgRefresh_MouseLeftButtonUp);
                    return;

                case 0x16:
                    ((Border) A_1).MouseEnter += new MouseEventHandler(this.Border_MouseEnter);
                    return;

                case 0x17:
                    this.x = (ScrollViewer) A_1;
                    return;

                case 0x18:
                    this.y = (StackPanel) A_1;
                    return;

                case 0x19:
                    this.z = (Image) A_1;
                    this.z.MouseLeftButtonUp += new MouseButtonEventHandler(this.btnExit_Click);
                    return;

                case 0x1a:
                    this.aa = (Image) A_1;
                    this.aa.MouseLeftButtonUp += new MouseButtonEventHandler(this.btnConnect_MouseLeftButtonUp);
                    return;

                case 0x1b:
                    this.ab = (Image) A_1;
                    this.ab.MouseLeftButtonUp += new MouseButtonEventHandler(this.btnDisConnect_MouseLeftButtonUp);
                    return;

                case 0x1c:
                    this.ac = (Image) A_1;
                    this.ac.MouseLeftButtonUp += new MouseButtonEventHandler(this.btnSend_MouseLeftButtonUp);
                    return;
            }
            this.ad = true;
        }

        [CompilerGenerated]
        private static void b()
        {
            Process.Start("https://thesafety.us/billing/?key=" + WebRequestManager.e(""));
        }

        public void b(AgentExitHandler A_0)
        {
            AgentExitHandler handler2;
            AgentExitHandler b = this.b;
            do
            {
                handler2 = b;
                AgentExitHandler handler3 = (AgentExitHandler) Delegate.Combine(handler2, A_0);
                b = Interlocked.CompareExchange<AgentExitHandler>(ref this.b, handler3, handler2);
            }
            while (b != handler2);
        }

        public void b(AgentMessageHandler A_0)
        {
            AgentMessageHandler handler2;
            AgentMessageHandler a = this.a;
            do
            {
                handler2 = a;
                AgentMessageHandler handler3 = (AgentMessageHandler) Delegate.Combine(handler2, A_0);
                a = Interlocked.CompareExchange<AgentMessageHandler>(ref this.a, handler3, handler2);
            }
            while (a != handler2);
        }

        [CompilerGenerated]
        private void b(object A_0)
        {
            this.aa.IsEnabled = true;
            this.ab.IsEnabled = true;
            this.aa.ToolTip = e.c("Reconnect");
            this.aa.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/reconnect.png"));
            this.ab.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/disconnect.png"));
            if (!ConfigManager.r() && (AgentUser.a().b() != LicenseType.Limited))
            {
                this.ac.IsEnabled = true;
                this.ac.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/send.png"));
            }
        }

        private void Border_MouseEnter(object A_0, MouseEventArgs A_1)
        {
            this.y.Focus();
        }

        private void btnConnect_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            if (ConnectionButton.d() != null)
            {
                if (ConnectionButton.d().e())
                {
                    ConnectionButton.d().g().t();
                }
                else
                {
                    ConnectionButton.d().j();
                }
            }
        }

        private void btnDisConnect_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            if (ConnectionButton.d() != null)
            {
                ConnectionButton.d().i();
            }
        }

        private void btnExit_Click(object A_0, RoutedEventArgs A_1)
        {
            if (((this.b != null) && this.c) || ((this.b != null) && (AgentUser.a().b() == LicenseType.Limited)))
            {
                this.b(A_0, new AgentExitEventArgs());
                ConfigManager.b();
            }
        }

        private void btnHelp_Click(object A_0, RoutedEventArgs A_1)
        {
            HelpWindow window = new HelpWindow();
            ConfigManager.a(window);
        }

        private void btnMainMenuClose_Click(object A_0, RoutedEventArgs A_1)
        {
            base.Visibility = Visibility.Hidden;
        }

        private void btnManagement_MouseUp(object A_0, MouseButtonEventArgs A_1)
        {
            ManagementWindow window = new ManagementWindow();
            window.Closed += new EventHandler(this.LicenseUpdated);
            ConfigManager.a(window);
        }

        private void btnMyAccount_Click(object A_0, RoutedEventArgs A_1)
        {
            if (af == null)
            {
                af = new ThreadStart(MainMenuPanel.b);
            }
            new Thread(af) { IsBackground = true }.Start();
        }

        private void btnMyIp_Click(object A_0, RoutedEventArgs A_1)
        {
            new Thread(new ThreadStart(this.a)) { IsBackground = true }.Start();
        }

        private void btnSend_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            SendMessage message = new SendMessage(ConnectionButton.d());
            ConfigManager.a(message);
        }

        private void btnSettings_Click(object A_0, RoutedEventArgs A_1)
        {
            OptionsWindow window = new OptionsWindow();
            window.Closed += new EventHandler(this.LicenseUpdated);
            ConfigManager.a(window);
        }

        private void button_Selecting(object A_0, EventArgs A_1)
        {
            SendOrPostCallback d = null;
            SendOrPostCallback callback2 = null;
            if (ConnectionButton.d().g().p())
            {
                if (d == null)
                {
                    d = new SendOrPostCallback(this.b);
                }
                this.d.Send(d, null);
            }
            else
            {
                if (callback2 == null)
                {
                    callback2 = new SendOrPostCallback(this.a);
                }
                this.d.Send(callback2, null);
            }
        }

        [CompilerGenerated]
        private void c()
        {
            this.y.IsEnabled = true;
            this.w.IsEnabled = true;
            this.x.IsEnabled = true;
        }

        [CompilerGenerated]
        private void c(object A_0)
        {
            if (AgentUser.a().b() == LicenseType.Limited)
            {
                this.m.IsEnabled = false;
                this.n.Foreground = Brushes.Gray;
            }
            else if ((AgentUser.a().b() == LicenseType.Premium) || (AgentUser.a().b() == LicenseType.Elite))
            {
                this.m.IsEnabled = true;
                this.n.Foreground = new SolidColorBrush(Color.FromRgb(14, 0x8a, 0xdf));
            }
        }

        [CompilerGenerated]
        private void d()
        {
            this.y.IsEnabled = false;
            this.w.IsEnabled = false;
            this.x.IsEnabled = false;
        }

        [CompilerGenerated]
        private void d(object A_0)
        {
            this.c = true;
        }

        private void e()
        {
            this.t.Content = e.c("Help");
            this.u.Content = e.c("HelpDesc");
            this.q.Content = e.c("Management");
            this.r.Content = e.c("ManagementDesc");
            this.k.Content = e.c("MyAccount");
            this.l.Content = e.c("MyAccountDesc");
            this.h.Content = e.c("MyIp");
            this.i.Content = e.c("MyIpDesc");
            this.n.Content = e.c("Settings");
            this.o.Content = e.c("SettingsDesc");
            this.v.Content = e.c("YourConnections");
            this.w.ToolTip = e.c("Refresh");
            this.z.ToolTip = e.c("Exit");
            this.ab.ToolTip = e.c("Disconnect");
            this.ac.ToolTip = e.c("Send");
            this.aa.ToolTip = e.c("Reconnect");
        }

        public void f()
        {
            this.y.Children.Clear();
            if (ae == null)
            {
                ae = new Func<ConnectionButton, string>(MainMenuPanel.a);
            }
            foreach (ConnectionButton button in ConfigManager.k().OrderBy<ConnectionButton, string>(ae))
            {
                this.y.Children.Add(button);
                button.b(new EventHandler<EventArgs>(this.button_Selecting));
                button.g().l().State.StateChanged += new EventHandler<StateChangedEventArgs>(this.State_StateChanged);
            }
            this.d.Send(new SendOrPostCallback(this.d), null);
        }

        private void Image_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            Process.Start("http://thesafety.us");
        }

        private void imgRefresh_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            if (ConfigManager.a())
            {
                ConfigManager.j();
            }
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this.ad)
            {
                this.ad = true;
                Uri resourceLocator = new Uri("/TheSafety;component/mainmenupanel.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        private void LicenseUpdated(object A_0, EventArgs A_1)
        {
            this.d.Send(new SendOrPostCallback(this.c), null);
        }

        private void State_StateChanged(object A_0, StateChangedEventArgs A_1)
        {
            if ((A_1.NewState.ConnectionState == VPNConnectionState.Running) || (A_1.NewState.ConnectionState == VPNConnectionState.Stopped))
            {
                this.button_Selecting(null, null);
            }
        }

        private void UserControl_Loaded(object A_0, RoutedEventArgs A_1)
        {
            this.d = SynchronizationContext.Current;
            this.LicenseUpdated(null, null);
            this.e.Content = "1.2";
            this.btnMyIp_Click(null, null);
        }
    }
}

